<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ page import="zhcmsPlus.vote.*" %> 
<%@ page import="zhcms.framework.GySplit" %> 
<%
//获取投票
request.setCharacterEncoding("utf-8");
String voteid=request.getParameter("voteid");
String votetype=request.getParameter("votetype");
String[] vote = request.getParameterValues("vote");

int ri=0;
VotePlus votep=new VotePlus();
Cookie votecookie=votep.getCookieByName(request,"zhcmsvotecookie");
ri=votep.updateVote(voteid, votetype, vote, votecookie);

//获取本次投票的结果
ArrayList<HashMap<String, String>> VoteList=new ArrayList<HashMap<String, String>>();
votep.getVote(voteid);
VoteList=votep.getVoteList();
Map<String,String> iS=new HashMap<String,String>();
iS =VoteList.get(0);
String VoteTitle=iS.get("Title");
String VoteText=iS.get("VoteText");
String VoteNum=iS.get("VoteNum");
String votev_Lock=iS.get("v_Lock");

GySplit a = new GySplit();
a.tool(VoteNum, "|");
String[] tempVoteNum = a.Show();
a = null;

GySplit b = new GySplit();
b.tool(VoteText, "|");
String[] tempVoteText = b.Show();
b = null;
 %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<style type="text/css">
<!--
td {
	font-size: 12px;
}
-->
</style>
<title>查看投票</title>
</head>
<body> 
<table width="600" border="0" align="center" cellpadding="0" cellspacing="1" bgcolor="#E8F7FF"> 
  <tr> 
    <td height="25" align="center" bgcolor="#C4ECFF">投票结果</td> 
  </tr> 
  <tr> 
    <td bgcolor="#FFFFFF">

    <table width="100%" border="0" align="center" cellpadding="10" cellspacing="0"> 
        <tr> 
          <td>投票题目：<%=VoteTitle%> <br> 
            <table width="100%" border="0" cellspacing="0" cellpadding="0"> 

			<%
			double voteCount=0;
			for(int i=0;i<tempVoteNum.length;i++)
			{
				voteCount=voteCount+Integer.parseInt(tempVoteNum[i]);
			}
			
			
			
			int k=0;
			for(int j=0;j<tempVoteText.length;j++)
			{
				double rate=0;
				if(voteCount>0)
				{
					rate=(Double.parseDouble(tempVoteNum[j]) / voteCount)*100;
				}
				System.out.println(rate);
			%>
              <tr> 
                <td width="200" height="25"> <%=(j+1)+". "+ tempVoteText[j]%> </td> 
                <td width="80"><%=" 票数："+tempVoteNum[j] %></td> 
                <td><img src="/template/images/public/bar<%=k%>.gif" width="<%=rate%>" height="9" align="center"> <%=rate+"%"%> </td> 
              </tr>
            <%
       k=k+1;
       if((k%5)==0)
		            {
		       k=1;
		            }
            }
             %>
            </table></td> 
        </tr> 
      </table></td> 
  </tr> 
  <tr bgcolor="#E8F7FF"> 
    <td height="22">&nbsp;
      	 <%
   //ri=0,表示本次投票不存在，=1表示锁定，=2表示已经投过了，=4表示投票成功
   if(ri==2)
   		{
   			out.println("你已经投过票！");
   		}
   else if(ri==4)
   		{
   			Cookie cookie1 = new Cookie("zhcmsvotecookie", "ok");
					cookie1.setMaxAge(1*24*60*60);
					//cookie1.setDomain("/");
					response.addCookie(cookie1);
   			out.println("<font color=800000>这是你第一次投票！</font>");
   		}
      	  %>
    </td> 
  </tr> 
</table> 
</body>
</html>
